﻿using MediatR;
using SheepStorage.API.Application.Command.SheepFieldCommand;
using SheepStorage.API.Application.Command.SheepManagementCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepFieldListCommandHandler
{
    public class SheepFieldCreateHandler : IRequestHandler<SheepFieldCreateCommand, Results<int>>
    {

        private readonly ISheepFieldService  sheepFieldService;

        public SheepFieldCreateHandler(ISheepFieldService sheepFieldService)
        {
            this.sheepFieldService = sheepFieldService;
        }

        /// <summary>
        /// 添加栏位
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public  async  Task<Results<int>> Handle(SheepFieldCreateCommand request, CancellationToken cancellationToken)
        {
            var entity = new SheepField()
            {
                BuildingManagementId = request.BuildingManagementId,
                SheepFieldName = request.SheepFieldName,
                Prefix = request.Prefix,
                SheepFieldCode = request.SheepFieldCode,
                SheepFieldNumber = request.SheepFieldNumber,
                SheepFieldId = request.SheepFieldId,
                AddType=request.AddType
            };
            var list = await sheepFieldService.AddSheepField(entity);
            return Results<int>.DataResult(list);
        }
    }
}
